<template>
  <div>
    <!-- 搜索栏区域 -->
    <el-card class="SearchCard" body-style="padding:0px">
      <el-row>
        <el-col :span="2">
          <div class="SearchTitle">条件搜索栏</div>
        </el-col>
        <el-col :span="4">
          <el-row>
            <el-col :span="10">
              <div class="SearchLable">搜索关键字</div>
            </el-col>
            <el-col :span="14">
              <div class="SearchLable">
                <el-input placeholder="请输入内容" v-model="queryInfo.srm" clearable @clear="clearEvent"></el-input>
              </div>
            </el-col>
          </el-row>
        </el-col>
        <el-col :span="2">
          <div class="SearchLable">
            <el-button size="medium" type="primary" @click="getSearchList()">搜索</el-button>
          </div>
        </el-col>
      </el-row>
    </el-card>
    <el-card class="TableCard" :body-style="{ padding: '0px' }">
      <div>
        <el-table
          :data="tableData"
          border
          :header-cell-style="{ 'text-align':'center',background: '#3F9DFD', color: '#FFF' }"
          :cell-style="{'text-align':'center'}"
          size="medium"
          stripe
          ref="table"
          :height="tableHeight"
          style="width: 100%;font-size:12px"
        >
          <el-table-column prop="drugCode" label="药品编码" width="100"></el-table-column>
          <el-table-column prop="name" label="操作" width="120">
            <template slot-scope="scope">
              <el-button
                type="text"
                size="mini"
                v-if="scope.row.geriatricDrugId>0"
                @click="showRuleAll(scope.row.geriatricDrugId,scope.row.id)"
              >查看</el-button>
              <el-button
                type="text"
                size="mini"
                style="margin-left:12px;"
                @click="showAddRule(scope.row.drugName,scope.row.drugCode)"
              >新增</el-button>
            </template>
          </el-table-column>
          <el-table-column prop="drugName" label="药品名称"></el-table-column>

          <!-- <el-table-column prop="cbrand" label="商品名"></el-table-column> -->
          <el-table-column label="给药类型">
            <template slot-scope="scope">
              <!-- {{(scope.row.nameType)}} -->
              <div v-if="scope.row.nameType==8">西药</div>
              <div v-else-if="scope.row.nameType==2">草药</div>
              <div v-else-if="scope.row.nameType==6">中成药</div>
              <!-- {{(scope.row.nameType==1)?"全身给药":(scope.row.nameType==2)?"局部给药":(scope.row.nameType==3)?"所有方式给药":"系统默认"}} -->
            </template>
          </el-table-column>
          <el-table-column prop="formName" label="剂型名称"></el-table-column>
          <el-table-column prop="drugSpec" label="药品规格"></el-table-column>
          <el-table-column prop="compName" label="药品生产厂家" width="220"></el-table-column>
          <el-table-column prop="approvalCode" label="批准文号"></el-table-column>
          <el-table-column prop="doseUnit" label="给药单位"></el-table-column>
        </el-table>
      </div>
      <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="queryInfo.pagenum"
          :page-sizes="[20, 50, 100]"
          :page-size="queryInfo.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="this.total"
          background
        ></el-pagination>
      </div>
    </el-card>

    <!-- 新增规则 -->
    <el-dialog title="新增规则" :visible.sync="dialogVisible" width="55%" :before-close="handleClose1">
      <div class="addRuleAdverse">
        <el-form
          :inline="true"
          :model="addRuleData"
          class="demo-form-inline addForm"
          label-width="150px"
          :rules="Formrules"
          ref="addRuleData"
        >
          <el-form-item label="药品名称">
            <el-input v-model="addRuleData.drugName" disabled size="medium"></el-input>
          </el-form-item>
          <el-form-item label="给药类型">
            <el-select v-model="addRuleData.routeType" size="medium" placeholder="请选择">
              <el-option
                v-for="item in RouteOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="给药途径">
            <el-input v-model="addRuleData.routeName" size="medium">
              <el-button slot="append" @click="showRoute(1)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="疾病编码">
            <el-input v-model="addRuleData.icdName" size="medium">
              <el-button slot="append" @click="showDisease(1)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="年龄低值" prop="ageLow">
            <el-input v-model.number="addRuleData.ageLow" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="年龄高值" prop="ageHigh">
            <el-input v-model.number="addRuleData.ageHigh" size="medium"></el-input>
          </el-form-item>

          <el-form-item label="年龄低值单位">
            <el-select v-model="addRuleData.ageLowUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="	年龄高值单位">
            <el-select v-model="addRuleData.ageHighUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="是否不等于年龄低值">
            <el-select v-model="addRuleData.unequalLow" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否不等于年龄高值">
            <el-select v-model="addRuleData.unequalHigh" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="年龄范围描述">
            <el-input v-model="addRuleData.ageDesc" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="警示级别">
            <el-select v-model="addRuleData.slCode" size="medium" placeholder="请选择">
              <el-option
                v-for="item in SlOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="肾">
            <el-radio v-model="addRuleData.renal" label="0">否</el-radio>
            <el-radio v-model="addRuleData.renal" label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="肝">
            <el-radio v-model="addRuleData.hepatic" label="0">否</el-radio>
            <el-radio v-model="addRuleData.hepatic" label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="心">
            <el-radio v-model="addRuleData.cardio" label="0">否</el-radio>
            <el-radio v-model="addRuleData.cardio" label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="肺pulm">
            <el-radio v-model="addRuleData.pulm" label="0">否</el-radio>
            <el-radio v-model="addRuleData.pulm" label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="神经">
            <el-radio v-model="addRuleData.neur" label="0">否</el-radio>
            <el-radio v-model="addRuleData.neur" label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="肺endo">
            <el-radio v-model="addRuleData.endo" label="0">否</el-radio>
            <el-radio v-model="addRuleData.endo" label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="f20">
            <el-select v-model="addRuleData.f20" placeholder="请选择">
              <el-option
                v-for="item in f20options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="警示信息">
            <el-input
              v-model="addRuleData.warning"
              type="textarea"
              :autosize="{ minRows: 3, maxRows:5}"
              size="medium"
            ></el-input>
          </el-form-item>
          <el-form-item label="问题详细信息描述">
            <el-input
              v-model="addRuleData.abstractDesc"
              type="textarea"
              :autosize="{ minRows: 3, maxRows:5}"
              size="medium"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="addRule()">新 增</el-button>
        <el-button @click="dialogVisible = false">取 消</el-button>
      </span>
    </el-dialog>

    <!-- 选择给药途径ID -->
    <el-dialog
      title="选择给药途径"
      :visible.sync="RouteVisible"
      class="editDialog"
      width="30%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:527px">
        <div class="addInput">
          <el-input v-model="routeData.srm" size="small" placeholder="请输入内容"></el-input>
          <el-button style="margin-right:8px" type="primary" size="small" @click="SearchRoute()">搜索</el-button>
        </div>
        <el-table
          :data="routeData.tableData"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
          @row-click="handleRow"
          @selection-change="handleSelectionChange"
        >
          <el-table-column label width="35">
            <template slot-scope="scope">
              <el-radio
                :label="scope.row"
                v-model="routeData.radioId"
                @change.native="handleSelectionChange(scope.row)"
              >&nbsp;</el-radio>
            </template>
          </el-table-column>

          <el-table-column prop="routeId" width="150" label="给药途径编码"></el-table-column>
          <el-table-column prop="routeName" label="给药途径名称"></el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        <div class="dialogBlock">
          <el-pagination
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"
            :current-page="routeData.page"
            :page-size="routeData.pageSize"
            layout="total, prev, pager, next"
            :total="routeData.total"
          ></el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button
              style="margin-right:8px"
              type="primary"
              size="small"
              @click="SelectRoute()"
            >确定</el-button>
            <el-button style="margin-right:8px" @click="RouteVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>
    <!-- 疾病诊断 -->
    <el-dialog
      title="疾病诊断"
      :visible.sync="DiseaseVisible"
      class="editDialog"
      width="30%"
      :before-close="handleClose"
    >
      <div style="width:100%;height:527px">
        <div class="addInput">
          <el-input v-model="DiseaseData.srm" size="small" placeholder="请输入内容"></el-input>
          <el-button
            style="margin-right:8px"
            type="primary"
            size="small"
            @click="SearchDisease()"
          >搜索</el-button>
        </div>
        <el-table
          :data="DiseaseData.tableData"
          stripe
          border
          height="400"
          style="width: 100%;font-size: 10px"
          :header-cell-style="{'text-align':'center'}"
          :row-style="{height:'40px'}"
          :cell-style="{'text-align':'center',padding:'0px'}"
          @row-click="handleRow1"
          @selection-change="handleSelectionChange1"
        >
          <el-table-column label width="35">
            <template slot-scope="scope">
              <el-radio
                :label="scope.row"
                v-model="DiseaseData.radioId"
                @change.native="handleSelectionChange1(scope.row)"
              >&nbsp;</el-radio>
            </template>
          </el-table-column>

          <el-table-column prop="zddm" width="150" label="诊断代码"></el-table-column>
          <el-table-column prop="zdmc" label="诊断名称"></el-table-column>
        </el-table>
        <!-- <el-pagination background layout="prev, pager, next" :total="1000"></el-pagination> -->
        <div class="dialogBlock">
          <el-pagination
            @size-change="handleSizeChange3"
            @current-change="handleCurrentChange3"
            current-page.sync="1"
            :page-size="100"
            layout="total, prev, pager, next"
            :total="DiseaseData.total"
          ></el-pagination>
        </div>
        <span slot="footer" class="dialog-footer">
          <div class="SortFoot">
            <el-button
              style="margin-right:8px"
              type="primary"
              size="small"
              @click="SelectDisease()"
            >确定</el-button>
            <el-button style="margin-right:8px" @click="RouteVisible = false" size="small">取消</el-button>
          </div>
        </span>
      </div>
    </el-dialog>
    <!-- 所有规则 -->
    <el-dialog
      title="所有老人用药规则"
      :visible.sync="RuleAllVisible"
      class="editDialog"
      width="55%"
      stripe
      :before-close="handleClose"
    >
      <div>
        <el-card style="height:530px">
          <el-table
            :data="RuleAllData.RuleAllTableList"
            :header-cell-style="{'text-align':'center'}"
            :cell-style="{'text-align':'center',padding:'0px'}"
            border
            stripe
            height="450"
            style="width: 100%"
          >
            <el-table-column type="index" label="序号" width="50"></el-table-column>
            <el-table-column label="操作" width="100">
              <template slot-scope="scope">
                <el-button
                  type="text"
                  style="margin-right:12px"
                  @click="showRuleOne(scope.row.id)"
                >查看</el-button>
                <el-button type="text" @click="open(scope.row.id)">删除</el-button>
              </template>
            </el-table-column>
            <el-table-column prop="drugName" label="药品名称" width="100"></el-table-column>
            <el-table-column label="给药类型" width="120">
              <template
                slot-scope="scope"
              >{{(scope.row.routeType==1)?"全身给药":(scope.row.routeType==2)?"局部给药":(scope.row.routeType==3)?"所有方式给药":"系统默认"}}</template>
            </el-table-column>
            <!-- <el-table-column prop="drugId" label="给药途径审查ID" width="100"></el-table-column> -->
            <el-table-column prop="routeIds" label="给药途径" width="160"></el-table-column>
            <el-table-column prop="icdCodes" label="疾病编码" width="180"></el-table-column>
            <!-- <el-table-column prop="routeDesc" label="给药途径名称" width="100"></el-table-column> -->
            <!-- <el-table-column prop="ageLow" label="年龄低值" width="100"></el-table-column> -->
            <el-table-column prop="slCode" label="警示级别" width="120">
              <template
                slot-scope="scope"
              >{{(scope.row.slCode==0)?"拦截":(scope.row.slCode==1)?"禁忌":(scope.row.slCode==2)?"不推荐":(scope.row.slCode==3)?"轻微":""}}</template>
            </el-table-column>
            <el-table-column prop="ageLow" label="年龄低值" width="150"></el-table-column>
            <el-table-column prop="unequalLow" label="是否不等于年龄低值" width="150">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.unequalLow==0)?"等于":(scope.row.unequalLow==1)?"不等于":""}}
              </template>
            </el-table-column>
            <el-table-column prop="ageLowUnit" label="年龄低值单位" width="150"></el-table-column>
            <el-table-column prop="ageHigh" label="年龄高值" width="150"></el-table-column>
            <el-table-column prop="unequalHigh" label="是否不等于年龄高值" width="150">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.unequalHigh==0)?"等于":(scope.row.unequalHigh==1)?"不等于":""}}
              </template>
            </el-table-column>
            <el-table-column prop="ageHighUnit" label="年龄高值单位" width="150"></el-table-column>

            <el-table-column prop="renal" label="肾" width="80">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.renal==0)?"否":(scope.row.renal==1)?"是":""}}
              </template>
            </el-table-column>
            <el-table-column prop="hepatic" label="肝" width="80">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.hepatic==0)?"否":(scope.row.hepatic==1)?"是":""}}
              </template>
            </el-table-column>
            <el-table-column prop="cardio" label="心" width="80">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.cardio==0)?"否":(scope.row.cardio==1)?"是":""}}
              </template>
            </el-table-column>
            <el-table-column prop="pulm" label="肺pulm" width="80">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.pulm==0)?"否":(scope.row.pulm==1)?"是":""}}
              </template>
            </el-table-column>
            <el-table-column prop="neur" label="神经" width="80">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.neur==0)?"否":(scope.row.neur==1)?"是":""}}
              </template>
            </el-table-column>
            <el-table-column prop="endo" label="肺endo" width="80">
              <template slot-scope="scope">
                <!-- 0-等于 1-不等于 -->
                {{(scope.row.endo==0)?"否":(scope.row.endo==1)?"是":""}}
              </template>
            </el-table-column>
            <el-table-column prop="f20" label="f20" width="80"></el-table-column>

            <el-table-column prop="ageDesc" label="年龄描述" width="150"></el-table-column>
            <el-table-column prop="warning" label="警示信息" width="150"></el-table-column>
            <el-table-column prop="abstractDesc" label="问题详细信息描述" width="150"></el-table-column>
          </el-table>
          <el-pagination
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            :current-page="1"
            :page-sizes="[20, 30, 50]"
            :page-size="100"
            layout="total, sizes, prev, pager, next, jumper"
            :total="RuleAllData.total"
          ></el-pagination>
        </el-card>
      </div>
    </el-dialog>
    <!-- 查看规则 -->
    <el-dialog
      title="老人用药规则"
      :visible.sync="showRuleOneVisible"
      width="55%"
      :before-close="handleClose"
    >
      <div class="addRuleAdverse">
        <el-form
          :inline="true"
          :model="showRuleOneData"
          class="demo-form-inline addForm"
          label-width="150px"
        >
          <el-form-item label="药品名称">
            <el-input v-model="showRuleOneData.drugName" disabled size="medium"></el-input>
          </el-form-item>
          <el-form-item label="给药类型">
            <el-select v-model="showRuleOneData.routeType" size="medium" placeholder="请选择">
              <el-option
                v-for="item in RouteOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="给药途径">
            <el-input v-model="showRuleOneData.routeName" size="medium">
              <el-button slot="append" @click="showRoute(1)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="疾病编码">
            <el-input v-model="showRuleOneData.icdName" size="medium">
              <el-button slot="append" @click="showDisease(1)">选择</el-button>
            </el-input>
          </el-form-item>
          <el-form-item label="年龄低值" prop="ageLow">
            <el-input v-model.number="showRuleOneData.ageLow" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="年龄高值" prop="ageHigh">
            <el-input v-model.number="showRuleOneData.ageHigh" size="medium"></el-input>
          </el-form-item>

          <el-form-item label="年龄低值单位">
            <el-select v-model="showRuleOneData.ageLowUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="	年龄高值单位">
            <el-select v-model="showRuleOneData.ageHighUnit" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowUnitOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="是否不等于年龄低值">
            <el-select v-model="showRuleOneData.unequalLow" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否不等于年龄高值">
            <el-select v-model="showRuleOneData.unequalHigh" size="medium" placeholder="请选择">
              <el-option
                v-for="item in LowOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="年龄范围描述">
            <el-input v-model="showRuleOneData.ageDesc" size="medium"></el-input>
          </el-form-item>
          <el-form-item label="警示级别">
            <el-select v-model="showRuleOneData.slCode" size="medium" placeholder="请选择">
              <el-option
                v-for="item in SlOptions"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="肾">
            <el-radio v-model="showRuleOneData.renal" :label="0">否</el-radio>
            <el-radio v-model="showRuleOneData.renal" :label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="肝">
            <el-radio v-model="showRuleOneData.hepatic" :label="0">否</el-radio>
            <el-radio v-model="showRuleOneData.hepatic" :label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="心">
            <el-radio v-model="showRuleOneData.cardio" :label="0">否</el-radio>
            <el-radio v-model="showRuleOneData.cardio" :label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="肺pulm">
            <el-radio v-model="showRuleOneData.pulm" :label="0">否</el-radio>
            <el-radio v-model="showRuleOneData.pulm" :label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="神经">
            <el-radio v-model="showRuleOneData.neur" :label="0">否</el-radio>
            <el-radio v-model="showRuleOneData.neur" :label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="肺endo">
            <el-radio v-model="showRuleOneData.endo" :label="0">否</el-radio>
            <el-radio v-model="showRuleOneData.endo" :label="1">是</el-radio>
          </el-form-item>
          <el-form-item label="f20">
            <el-select v-model="showRuleOneData.f20" placeholder="请选择">
              <el-option
                v-for="item in f20options"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="警示信息">
            <el-input
              v-model="showRuleOneData.warning"
              type="textarea"
              :autosize="{ minRows: 3, maxRows:5}"
              size="medium"
            ></el-input>
          </el-form-item>
          <el-form-item label="问题详细信息描述">
            <el-input
              v-model="showRuleOneData.abstractDesc"
              type="textarea"
              :autosize="{ minRows: 3, maxRows:5}"
              size="medium"
            ></el-input>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="updateRuleOne()">更 新</el-button>
        <el-button @click="showAdultRuleOneVisible = false">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import {
  getRuleListAge,
  addRuleInfoAge,
  getRouteJson,
  showRuleAllAge,
  showRuleOneAge,
  updateRuleOneAge,
  deleteRuleAge,
  showRuleDiseaseAge,
} from "@/api/rad";
export default {
  data() {
    var checkAgeLow = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("年龄不能为空"));
      }

      if (!Number.isInteger(value)) {
        callback(new Error("请输入数字值"));
      } else {
        if (value < 0) {
          callback(new Error("年龄必须大于0"));
        } else {
          callback();
        }
      }
    };
    var checkAgeHigh = (rule, value, callback) => {
      if (!value) {
        return callback(new Error("年龄不能为空"));
      }
      if (!Number.isInteger(value)) {
        callback(new Error("请输入数字值"));
      } else {
        if (value < 0) {
          callback(new Error("年龄必须大于0"));
        } else {
          callback();
        }
      }
    };
    return {
      multipleSelection: {},
      tableHeight: 250,

      queryInfo: {
        srm: "",
        page: 1,
        pageSize: 20,
      },
      total: 0,
      tableData: [],
      SlOptions: [
        {
          value: 0,
          label: "拦截",
        },
        {
          value: 1,
          label: "禁忌",
        },
        {
          value: 2,
          label: "不推荐",
        },
        {
          value: 3,
          label: "轻微",
        },
      ],
      RouteOptions: [
        {
          value: 1,
          label: "全身给药",
        },
        {
          value: 2,
          label: "局部给药",
        },
        {
          value: 3,
          label: "所有方式给药",
        },
      ],
      f20options: [
        {
          value: 1,
          label: 1,
        },
        {
          value: 2,
          label: 2,
        },
        {
          value: 3,
          label: 3,
        },
        {
          value: 4,
          label: 4,
        },
        {
          value: 5,
          label: 5,
        },
      ],
      LowOptions: [
        {
          value: 0,
          label: "等于",
        },
        {
          value: 1,
          label: "不等于",
        },
      ],
      LowUnitOptions: [
        {
          value: "周",
          label: "周",
        },
        {
          value: "月",
          label: "月",
        },
        {
          value: "年",
          label: "年",
        },
      ],
      dialogVisible: false,
      RouteVisible: false,
      routeData: {
        srm: "",
        page: 1,
        pageSize: 10,
        load: 0,
        total: 0,
        tableData: [],
        radioId: [],
      },
      addRuleData: {
        id: "",
        drugName: "",
        routeType: "",
        routeIds: "",
        ageLow: "",
        unequalLow: "",
        ageLowUnit: "",
        ageHigh: "",
        unequalHigh: "",
        ageHighUnit: "",
        ageDesc: "",
        renal: "",
        hepatic: "",
        cardio: "",
        pulm: "",
        neur: "",
        endo: "",
        f20: "",
        icdCodes: "",
        icdName: "",
        slCode: "",
        warning: "",
        abstractDesc: "",
        drugCode: "",
      },
      RuleAllVisible: false,
      RuleAllData: {
        geriatricDrugId: "",
        // routeDrugId: "",
        page: 1,
        pageSize: 20,
        total: 0,
        RuleAllTableList: [],
      },
      showRuleOneVisible: false,
      showRuleOneData: {
        id: "",
        drugId: "",
        drugName: "",
        routeType: "",
        routeIds: "",
        ageLow: "",
        unequalLow: "",
        ageLowUnit: "",
        ageHigh: "",
        unequalHigh: "",
        ageHighUnit: "",
        ageDesc: "",
        renal: "",
        hepatic: "",
        cardio: "",
        pulm: "",
        neur: "",
        endo: "",
        f20: "",
        icdCodes: "",
        slCode: "",
        warning: "",
        abstractDesc: "",
      },
      DiseaseVisible: false,
      DiseaseData: {
        srm: "",
        page: 1,
        pageSize: 20,
        load: 0,
        total: 0,
        tableData: [],
        radioId: [],
      },
      Formrules: {
        ageLow: [{ validator: checkAgeLow, trigger: "blur" }],
        ageHigh: [{ validator: checkAgeHigh, trigger: "blur" }],
        // routeType: [{ validator: checkrouteType, trigger: "blur" }],
        // routeName: [{ validator: checkrouteName, trigger: "blur" }],
        // zdmc: [{ validator: checkzdmc, trigger: "blur" }],

        // unequalLow: [{ validator: checkunequalLow, trigger: "blur" }],
        // unequalHigh: [{ validator: checkunequalHigh, trigger: "blur" }],
        // ageLowUnit: [{ validator: checkageLowUnit, trigger: "blur" }],
        // // 年龄低值单位
        // ageHighUnit: [{ validator: checkageHighUnit, trigger: "blur" }],
        // slCode: [{ validator: checkslCode, trigger: "blur" }],
        // warning: [{ validator: checkwarning, trigger: "blur" }],
        // abstractDesc: [{ validator: checkabstractDesc, trigger: "blur" }]
      },
    };
  },
  mounted: function () {
    this.$nextTick(function () {
      this.tableHeight =
        window.innerHeight - this.$refs.table.$el.offsetTop - 50;
      // 监听窗口大小变化
      let self = this;
      window.onresize = function () {
        self.tableHeight =
          window.innerHeight - self.$refs.table.$el.offsetTop - 50;
      };
    });
  },
  created: function () {
    this.getRuleListAge();
  },
  methods: {
    handleClose(done) {
      done();
    },
    handleClose1(done) {
      this.clearAddRuleData();
      done();
    },
    handleSizeChange(newSize) {
      this.queryInfo.pageSize = newSize;
      console.log(this.queryInfo);
      this.getRuleListAge();
    },

    handleCurrentChange(newPage) {
      this.queryInfo.page = newPage;
      console.log(this.queryInfo);
      this.getRuleListAge();
    },
    handleSizeChange1(newSize) {
      this.routeData.pageSize = newSize;

      this.getRouteJson();
    },
    handleCurrentChange1(newPage) {
      this.routeData.page = newPage;
      this.getRouteJson();
    },
    handleSizeChange2(newSize) {
      this.RuleAllData.pageSize = newSize;
      this.showRuleAllRoute();
    },
    handleCurrentChange2(newPage) {
      this.RuleAllData.page = newPage;
      this.showRuleAllRoute();
    },
    handleSizeChange3(newSize) {
      this.DiseaseData.pageSize = newSize;
      this.showRuleDiseaseAge();
    },
    handleCurrentChange3(newPage) {
      this.DiseaseData.page = newPage;
      this.showRuleDiseaseAge();
    },
    async getRuleListAge() {
      let res = await this.$rad.getRuleListAge({
        srm: this.queryInfo.srm,
        page: this.queryInfo.page,
        pageSize: this.queryInfo.pageSize,
      });
      (this.tableData = res.rows), (this.total = res.total);
      console.log(res.rows);
    },
    getSearchList() {
      this.queryInfo.page = 1;
      this.getRuleListAge();
    },
    clearEvent() {},
    showAddRule(drugName, drugCode) {
      this.addRuleData.drugName = drugName;
      this.addRuleData.drugCode = drugCode;
      this.dialogVisible = true;
    },
    showRoute(load) {
      this.RouteVisible = true;
      this.routeData.load = load;
      this.getRouteJson();
    },
    async getRouteJson() {
      let res = await this.$rad.getRouteJson({
        srm: this.routeData.srm,
        page: this.routeData.page,
        pageSize: this.routeData.pageSize,
      });
      console.log(res);
      this.routeData.tableData = res.rows;
      this.routeData.total = res.total;
    },
    SelectRoute() {
      if (this.routeData.radioId.length == 0) {
        this.$message({
          type: "warning",
          message: "请选择给药途径",
        });
      } else {
        if (this.routeData.load == 1) {
          console.log(this.routeData.radioId);
          this.addRuleData.routeName = this.routeData.radioId.routeName;
          this.addRuleData.routeIds = this.routeData.radioId.routeId;
        } else if (this.routeData.load == 2) {
          this.showRuleOneData.routeName = this.routeData.radioId.routeName;
          this.showRuleOneData.routeId = this.routeData.radioId.routeId;
        }
        console.log(this.routeData.radioId);
        this.RouteVisible = false;
      }
    },

    async addRule() {
      console.log(this.addRuleData);
      let res = await this.$rad.addRuleInfoAge({
        drugName: this.addRuleData.drugName,
        routeType: this.addRuleData.routeType,
        routeIds: this.addRuleData.routeIds,
        ageLow: this.addRuleData.ageLow,
        unequalLow: this.addRuleData.unequalLow,
        ageLowUnit: this.addRuleData.ageLowUnit,
        ageHigh: this.addRuleData.ageHigh,
        unequalHigh: this.addRuleData.unequalHigh,
        ageHighUnit: this.addRuleData.ageHighUnit,
        ageDesc: this.addRuleData.ageDesc,
        renal: this.addRuleData.renal,
        hepatic: this.addRuleData.hepatic,
        cardio: this.addRuleData.cardio,
        pulm: this.addRuleData.pulm,
        neur: this.addRuleData.neur,
        endo: this.addRuleData.endo,
        f20: this.addRuleData.f20,
        icdCodes: this.addRuleData.icdCodes,
        slCode: this.addRuleData.slCode,
        warning: this.addRuleData.warning,
        abstractDesc: this.addRuleData.abstractDesc,
        drugCode: this.addRuleData.drugCode,
      });
      if (res.code == 1) {
        this.dialogVisible = false;
        this.getRuleListAge();
        this.clearAddRuleData();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "error",
          message: res.msg,
        });
      }
    },
    showRuleAll(geriatricDrugId, id) {
      this.RuleAllData.geriatricDrugId = geriatricDrugId;
      console.log(this.RuleAllData.geriatricDrugId);
      this.RuleAllData.id = id;
      this.RuleAllVisible = true;
      this.showRuleAllRoute();
    },
    async showRuleAllRoute() {
      let res = await this.$rad.showRuleAllAge({
        drugId: this.RuleAllData.geriatricDrugId,
        page: this.RuleAllData.page,
        pageSize: this.RuleAllData.pageSize,
      });
      this.RuleAllData.RuleAllTableList = res.rows;
      this.RuleAllData.total = res.total;
      console.log(this.RuleAllData.RuleAllTableList);
    },
    showRuleOne(id) {
      this.showRuleOneData.id = id;
      console.log(id);
      this.showRuleOneVisible = true;
      this.showRuleOneRoute();
    },
    async showRuleOneRoute() {
      let res = await this.$rad.showRuleOneAge({
        id: this.showRuleOneData.id,
      });
      // console.log(res);
      (this.showRuleOneData.id = res.data.id),
        (this.showRuleOneData.drugId = res.data.drugId),
        (this.showRuleOneData.drugName = res.data.drugName),
        (this.showRuleOneData.routeType = res.data.routeType),
        (this.showRuleOneData.routeIds = res.data.routeIds),
        (this.showRuleOneData.ageLow = res.data.ageLow),
        (this.showRuleOneData.unequalLow = res.data.unequalLow),
        (this.showRuleOneData.ageLowUnit = res.data.ageLowUnit),
        (this.showRuleOneData.ageHigh = res.data.ageHigh),
        (this.showRuleOneData.unequalHigh = res.data.unequalHigh),
        (this.showRuleOneData.ageHighUnit = res.data.ageHighUnit),
        (this.showRuleOneData.ageDesc = res.data.ageDesc),
        (this.showRuleOneData.renal = res.data.renal),
        (this.showRuleOneData.hepatic = res.data.hepatic),
        (this.showRuleOneData.cardio = res.data.cardio),
        (this.showRuleOneData.pulm = res.data.pulm),
        (this.showRuleOneData.neur = res.data.neur),
        (this.showRuleOneData.endo = res.data.endo),
        (this.showRuleOneData.f20 = res.data.f20),
        (this.showRuleOneData.icdCodes = res.data.icdCodes),
        (this.showRuleOneData.slCode = res.data.slCode),
        (this.showRuleOneData.warning = res.data.warning),
        (this.showRuleOneData.abstractDesc = res.data.abstractDesc);
      console.log(this.showRuleOneData);
    },
    async updateRuleOne() {
      // console.log(this.showRuleOneData);
      let res = await this.$rad.updateRuleOneAge({
        id: this.showRuleOneData.id,
        drugName: this.showRuleOneData.drugName,
        routeType: this.showRuleOneData.routeType,
        routeIds: this.showRuleOneData.routeIds,
        ageLow: this.showRuleOneData.ageLow,
        unequalLow: this.showRuleOneData.unequalLow,
        ageLowUnit: this.showRuleOneData.ageLowUnit,
        ageHigh: this.showRuleOneData.ageHigh,
        unequalHigh: this.showRuleOneData.unequalHigh,
        ageHighUnit: this.showRuleOneData.ageHighUnit,
        ageDesc: this.showRuleOneData.ageDesc,
        renal: this.showRuleOneData.renal,
        hepatic: this.showRuleOneData.hepatic,
        cardio: this.showRuleOneData.cardio,
        pulm: this.showRuleOneData.pulm,
        neur: this.showRuleOneData.neur,
        endo: this.showRuleOneData.endo,
        f20: this.showRuleOneData.f20,
        icdCodes: this.showRuleOneData.icdCodes,
        slCode: this.showRuleOneData.slCode,
        warning: this.showRuleOneData.warning,
        abstractDesc: this.showRuleOneData.abstractDesc,
        drugCode: this.showRuleOneData.drugCode,
      });
      if (res.code == 1) {
        this.showRuleOneVisible = false;
        this.showRuleAllRoute();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "success",
          $message: res.msg,
        });
      }
    },
    open(id) {
      this.$confirm("此操作将永久删除该规则, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.deleteRuleAge(id);
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    async deleteRuleAge(id) {
      console.log(id + "  " + this.RuleAllData.geriatricDrugId);
      let res = await this.$rad.deleteRuleAge({
        id: id,
        drugId: this.RuleAllData.geriatricDrugId,
      });
      console.log(res);
      if (res.code == 1) {
        this.showRuleAllRoute();
        this.getRuleListAge();
        return this.$message({
          type: "success",
          message: res.msg,
        });
      } else {
        return this.$message({
          type: "success",
          $message: res.msg,
        });
      }
    },
    clearAddRuleData() {
      this.addRuleData.id = "";
      this.addRuleData.drugName = "";
      this.addRuleData.routeType = "";
      this.addRuleData.routeName = "";
      this.addRuleData.routeIds = "";
      this.addRuleData.ageLow = "";
      this.addRuleData.unequalLow = "";
      this.addRuleData.ageLowUnit = "";
      this.addRuleData.ageHigh = "";
      this.addRuleData.unequalHigh = "";
      this.addRuleData.ageHighUnit = "";
      this.addRuleData.ageDesc = "";
      this.addRuleData.renal = "";
      this.addRuleData.hepatic = "";
      this.addRuleData.cardio = "";
      this.addRuleData.pulm = "";
      this.addRuleData.neur = "";
      this.addRuleData.endo = "";
      this.addRuleData.f20 = "";
      this.addRuleData.icdCodes = "";
      this.addRuleData.icdName = "";
      this.addRuleData.slCode = "";
      this.addRuleData.warning = "";
      this.addRuleData.abstractDesc = "";
      this.addRuleData.drugCode = "";
    },
    showDisease(load) {
      this.DiseaseData.load = load;
      this.DiseaseVisible = true;
      this.showRuleDiseaseAge();
    },
    async showRuleDiseaseAge() {
      let res = await this.$rad.showRuleDiseaseAge({
        srm: this.DiseaseData.srm,
        page: this.DiseaseData.page,
        pageSize: this.DiseaseData.pageSize,
      });
      console.log(res);
      this.DiseaseData.tableData = res.rows;
      this.DiseaseData.total = res.total;
    },
    SelectDisease() {
      if (this.DiseaseData.radioId.length == 0) {
        this.$message({
          type: "warning",
          message: "请选择疾病诊断",
        });
      } else {
        if (this.DiseaseData.load == 1) {
          console.log(this.DiseaseData.radioId);
          this.addRuleData.icdName = this.DiseaseData.radioId.zdmc;
          this.addRuleData.icdCodes = this.DiseaseData.radioId.zddm;
        } else if (this.DiseaseData.load == 2) {
          // console.log
          this.showRuleOneData.icdName = this.DiseaseData.radioId.zdmc;
          this.showRuleOneData.icdCodes = this.DiseaseData.radioId.zddm;
        }

        this.DiseaseVisible = false;
      }
    },
    SearchRoute() {
      this.routeData.page = 1;
      this.getRouteJson();
    },
    SearchDisease() {
      this.DiseaseData.page = 1;
      this.showRuleDiseaseAge();
    },
    handleRow(row) {
      console.log(row);
      this.routeData.radioId = row;
      this.multipleSelection = row;
    },
    handleSelectionChange(val) {
      console.log(res);
      this.multipleSelection = val;
    },
    handleRow1(row) {
      console.log(row);
      this.DiseaseData.radioId = row;
      this.multipleSelection = row;
    },
    handleSelectionChange1(val) {
      console.log(res);
      this.multipleSelection = val;
    },
  },
};
</script>
<style scoped>
.SearchCard {
  height: 50px;
  font-size: 12px;
}
.SearchTitle {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
  border-right: 1px solid #c2c2c2;
}
.SearchLable {
  height: 50px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.TableCard {
  margin-left: 3px;
  margin-top: 2px;
}
.block {
  text-align: center;
  margin-top: 12px;
  margin-bottom: 12px;
}
.editDialog >>> .el-dialog__header {
  margin-bottom: 0px;
}
.editDialog >>> .el-dialog__body {
  padding-left: 0px;
  padding-right: 0px;
}
.addInput {
  height: 45px;
  display: flex;
  align-items: center;
}
.SortFoot {
  height: 50px;
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.addInput >>> .el-input {
  width: 40%;
  margin-left: 8px;
}
.addInput >>> .el-button {
  margin-left: 8px;
}
.dialogBlock {
  margin-top: 0px;
  margin-bottom: 0px;
}
.addForm >>> .el-form-item__content {
  width: 200px;
}
</style>